package cz.vargagab.mvc;

 import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cz.vargagab.domain.RmiNode;
import cz.vargagab.repo.InternalServerService;
import cz.vargagab.repo.ExternalServerService;

@Controller
public class HomePageController
{
    @Autowired
    private ExternalServerService externalServerService;

    @Autowired
    InternalServerService internalServerService;

    @Autowired
    RmiNode thisNode;
    
    @RequestMapping(value="/",method=RequestMethod.GET)
    public String index(Model model)
    {
    	//naplnit model atributami, ktore sa zobrazia v index.jsp
    	model.addAttribute("thisNode", thisNode);
    	model.addAttribute("currentValue", externalServerService.readData(thisNode.getName()));
    	model.addAttribute("rmiNodes",internalServerService.getMapOfNodes());
    	model.addAttribute("lastChange",internalServerService.getLastChangedBy());
    	model.addAttribute("lastChangeDate",internalServerService.getLastChangedDate());
    	model.addAttribute("logs", internalServerService.getLog());
        return "index";
    }

    //Getters & Setters
	public RmiNode getThisNode() {
		return thisNode;
	}
	public void setThisNode(RmiNode thisNode) {
		this.thisNode = thisNode;
	}

	public ExternalServerService getExternalServerService() {
		return externalServerService;
	}
	public void setExternalServerService(ExternalServerService externalServerService) {
		this.externalServerService = externalServerService;
	}

	public InternalServerService getInternalServerService() {
		return internalServerService;
	}
	public void setInternalServerService(InternalServerService internalServerService) {
		this.internalServerService = internalServerService;
	}

}
